<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

class CorePHPInfo {
	var $_info;
	var $_content;
	
	//constructor
	function CorePHPInfo() {
		
	}
	
	//methods
	function parse() {
		ob_start();
		phpinfo();
		$content = ob_get_contents();
		ob_end_clean();
		
		$content = str_replace('border: 1px', '', $content);
		ereg('<body>(.*)</body>', $content, $regs);
		
		$this->_content = $regs['1'];
	}
	
	function getDBInformation() {
		global $adb;
		
		$row = $adb->getRow("select now() as datetime");
		
		$info = array();
		$info['db_server'] = $adb->dbHostName;
		$info['db_ip'] = gethostbyname($adb->dbHostName);
		$info['db_version'] = 'MySQL ' . (function_exists('mysql_get_server_info') ? mysql_get_server_info() : '');
		$info['db_date'] = $row['datetime'];
		
		return $info;
	}
	
	function getServerInformation() {
		list($system, $host, $kernel) = preg_split('/[\s,]+/', @exec('uname -a'), 5);
		
		$info = array();
		$info['date'] = date('Y-m-d H:i:s');
		$info['system'] = $system;
		$info['host'] = $host;
		$info['kernel'] = $kernel;
		$info['ip'] = gethostbyname($host);
		$info['uptime'] = @exec('uptime');
		$info['http_server'] = $_SERVER['SERVER_SOFTWARE'];
		$info['php'] = PHP_VERSION;
		$info['zend'] = (function_exists('zend_version') ? zend_version() : '');
		
		return $info;
	}
	
	function getInformation() {
		$info_db = $this->getDBInformation();
		$info_sv = $this->getServerInformation();
		$this->_info = array_merge($info_db, $info_sv);
		
		return $this->_info;
	}
	
	function getContent() {
		$this->parse();
		return $this->_content;
	}
	
	function output() {
		echo $this->_content;
	}
}
//
?>